//
// Created by chaseaishang on 23-4-8.
//
#include "test.h"
#include "imgui.h"
#include "ApplicationEvent.h"

namespace test
{
    TestMenu*TestMenu::s_Instance;
    TestMenu::TestMenu(Test*& currentTestPtr,GLFWwindow *window)
            :m_CurrentTest(currentTestPtr),m_window(window)
    {
        TestMenu::s_Instance=this;
    }


    void TestMenu::OnImGuiRender()
    {
        for (auto& test : m_Tests) {
            if (ImGui::Button(test.first.c_str()))
            {
                m_CurrentTest = test.second();
            }
        }
    }

//bool fn(WindowCloseEvent& e)
//{
//    return true;
//}
//    dispatcher.Dispatch<WindowCloseEvent,bool(WindowCloseEvent&)>(fn);
#define BIND_EVENT_FN(x) std::bind(&TestMenu::x, this, std::placeholders::_1)
    void TestMenu::OnEvent(Event &e)
    {
        EventDispatcher dispatcher(e);

        dispatcher.Dispatch<WindowCloseEvent>(
                [&](WindowCloseEvent& e)
                {
                    std::cout<<"out";
                    return true;
                });

        dispatcher.Dispatch<WindowResizeEvent>(
                [&](WindowResizeEvent&e)
                {
                    return false;
                }
                );
//KeyPressedEvent
//KeyReleasedEvent
        if(m_CurrentTest!= this)
        {
            m_CurrentTest->OnEvent(e);
        }



    }


}